Skip to content

Allow move-only types as suites. #619

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 21, 2024
Merged

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Aug 19, 2024

This PR enables using move-only types as suites. For example:

@Suite struct NumberOfBeesTests: ~Copyable {
  @Test consuming func countBees() {
    var count = 0
    for species in allSpecies {
      if species is Bee {
        count += species.populationCount
      }
    }

    #expect(count > 0)
  }
}

Move-only types have a number of constraints in Swift, and those constraints aren't lifted in a test target, but generally speaking a move-only type should be able to do all the things any other type can do as a test suite.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR enables using move-only types as suites. For example:

```swift
@suite struct NumberOfBeesTests: ~Copyable {
  @test consuming func countBees() async {
    var count = 0
    for species in allSpecies {
      if species is Bee {
        count += species.populationCount
      }
    }

	#expect(count > 0)
  }
}
```

Move-only types have a number of constraints in Swift, and those constraints
aren't lifted in a test target, but generally speaking a move-only type should
be able to do all the things any other type can do _as a test suite_.
@grynspan
Copy link
Contributor Author

@swift-ci please test

@grynspan grynspan changed the base branch from main to main-next August 21, 2024 00:16
@grynspan grynspan merged commit cd91e93 into main-next Aug 21, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/move-only-suites branch August 21, 2024 00:16
grynspan added a commit that referenced this pull request Aug 21, 2024
This PR fixes a conflict between #610 and #619. #610 added a string cache to
`TypeInfo` using `ObjectIdentifier` instances as keys. #619 added support for
move-only types to `TypeInfo`. Due to rdar://134276458, move-only types cannot
be used with `ObjectIdentifier`. This PR uses `UInt` instead until that issue
can be resolved in a future stdlib update.
@grynspan grynspan mentioned this pull request Aug 21, 2024
2 tasks
grynspan added a commit that referenced this pull request Aug 21, 2024
This PR fixes a conflict between #610 and #619. #610 added a string
cache to `TypeInfo` using `ObjectIdentifier` instances as keys. #619
added support for move-only types to `TypeInfo`. Due to
rdar://134276458, move-only types cannot be used with
`ObjectIdentifier`. This PR uses `UInt` instead until that issue can be
resolved in a future stdlib update.

### Checklist:

- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.
@grynspan grynspan added this to the Swift 6.1 milestone Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request public-api Affects public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants